package com.galaxy.samson.student.domain;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import javax.persistence.*;

/**
 * Created by IntelliJ IDEA.
 * User: arunachalam
 * Date: 2/6/12
 * Time: 6:51 PM
 * To change this template use File | Settings | File Templates.
 */

@NamedQueries({
        @NamedQuery(name = "searchByRollNumber",
        query = "select s from Student s where s.rollNumber=:rollNumber"),
        @NamedQuery(name = "searchByRegisterNumber",
                query = "select s from Student s where s.registerNumber=:registerNumber"),
        @NamedQuery(name = "searchByDepartment",
                query = "select s from Student s where s.department=:department"),
        @NamedQuery(name = "searchByName",
                query = "select s from Student s where s.name=:name"),
        @NamedQuery(name = "removeAll",
                query = "delete from Student s")

        /*@NamedQuery(name = "searchByCity",
                query = "select s from Student s where s.city=:city")*/
})
@Entity
@Table(name = "Student")
public class Student
{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    @Column(nullable = false)
    private String name;
    @Column(nullable = false)
    private int rollNumber;
    @Column(nullable = false)
    private String registerNumber;
    @Column(nullable = false)
    private String department;
    @Column(nullable = false)
    private String year;
    @Column(nullable = false)
    private String fatherName;
    @Column(nullable = false)
    private String roomNumber;
    @Column(nullable = false)
    private String messType;
    @OneToOne(mappedBy = "student" ,cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    private Address address;

    public Student()
    {
    }

    public Student(String name, int rollNumber, String registerNumber, String department, String year, String fatherName, String roomNumber, String messType, Address address)
    {
        this.name = name;
        this.rollNumber = rollNumber;
        this.registerNumber = registerNumber;
        this.department = department;
        this.year = year;
        this.fatherName = fatherName;
        this.roomNumber = roomNumber;
        this.messType = messType;
        this.address = address;
    }

    public int getId()
    {
        return id;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public int getRollNumber()
    {
        return rollNumber;
    }

    public void setRollNumber(int rollNumber)
    {
        this.rollNumber = rollNumber;
    }

    public String getRegisterNumber()
    {
        return registerNumber;
    }

    public void setRegisterNumber(String registerNumber)
    {
        this.registerNumber = registerNumber;
    }

    public String getDepartment()
    {
        return department;
    }

    public void setDepartment(String department)
    {
        this.department = department;
    }

    public String getYear()
    {
        return year;
    }

    public void setYear(String year)
    {
        this.year = year;
    }

    public String getFatherName()
    {
        return fatherName;
    }

    public void setFatherName(String fatherName)
    {
        this.fatherName = fatherName;
    }

    public String getRoomNumber()
    {
        return roomNumber;
    }

    public void setRoomNumber(String roomNumber)
    {
        this.roomNumber = roomNumber;
    }

    public String getMessType()
    {
        return messType;
    }

    public void setMessType(String messType)
    {
        this.messType = messType;
    }

    public Address getAddress()
    {
        return address;
    }

    public void setAddress(Address address)
    {
        this.address = address;
    }

    @Override
    public int hashCode()
    {
        return HashCodeBuilder.reflectionHashCode(this);
    }

    @Override
    public boolean equals(Object o)
    {
        if(this == o) return true;

        if (o instanceof Student) {
            Student otherObject = (Student) o;


            return EqualsBuilder.reflectionEquals(this, otherObject);
        }
        return false;
    }

    @Override
    public String toString()
    {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}



